// components/Goods/goods.js
const app = getApp(),
  _ = require('../../pages/Common/underscore.js'),
  WxParse = require('../wxParse/wxParse.js'),
  {
    $resHost
  } = app.globalData;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isComment: {
      type: Boolean,
      value: false
    },
    comments: {
      type: Array,
      value: [],
      observer(comments) {
        this.setComments(comments);
      }
    },
    articleInfo: {
      type: Object,
      value: {},
      observer(articleInfo) {
        this.setArticle(articleInfo);
      }
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    title: '',
    formatCreateAt: '',
    employeeName: '',
    content: '',
    views: 0,
    list: [],
    isComment: false,
    none: `${$resHost}/img/none.png`
  },
  /**
   * 组件的方法列表
   */
  methods: {
    setComments(comments) {
      this.setData({
        list: comments
      });
    },
    setArticle(articleInfo) {
      let article = articleInfo.content;
      WxParse.wxParse('article', 'html', article, this, 5);
      this.setData({
        title: articleInfo.title || '',
        formatCreateAt: articleInfo.formatCreateAt || '',
        employeeName: articleInfo.employeeName || '',
        content: articleInfo.content || '',
        views: articleInfo.views || 0
        // goodsBody: this.data.goodsBody.replace(/(\n\r?)/g, '<br>').replace(/\s/g, '&nbsp;')
      });
    },
    comment() {
      this.triggerEvent('opencomment', true);
    }
  }
});